package com.quickcode.example.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * Created by 张波 on 2019/10/25.
 */
@Slf4j
public class CallableExample {

    static class CallableThread implements Callable<String> {

        @Override
        public String call() throws Exception {
            log.info("run call");
            Thread.sleep(5000);
            return "ok";
        }
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executorService = Executors.newCachedThreadPool();

        Future<String> submit = executorService.submit(new CallableThread());
        log.info("main start");
        Thread.sleep(2000);
        String result = submit.get();
        log.info("result:{}",result);

        executorService.shutdown();
    }

}
